package com.wjpeng.wms.web.controller;

import com.wjpeng.wms.domain.StockIncomeBill;
import com.wjpeng.wms.query.StockIncomeBillQueryObject;
import com.wjpeng.wms.service.IStockIncomeBillService;
import com.wjpeng.wms.service.IDepotService;
import com.wjpeng.wms.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("stockIncomeBill")
public class StockIncomeBillController {
    @Autowired
    private IStockIncomeBillService stockIncomeBillService;

    @Autowired
    private IDepotService depotService;


    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") StockIncomeBillQueryObject qo) {
        model.addAttribute("result",stockIncomeBillService.result(qo));
        model.addAttribute("depots",depotService.list());
        return "stockIncomeBill/list";
    }

    @RequestMapping("input")
    public String input(Model model,Long id){
        if(id != null){
            model.addAttribute("entity",stockIncomeBillService.get(id));

        }
        model.addAttribute("depots",depotService.list());
        return "stockIncomeBill/input";
    }

    @RequestMapping("view")
    public String view(Model model,Long id){
        if(id != null){
            model.addAttribute("entity",stockIncomeBillService.get(id));

        }
        model.addAttribute("depots",depotService.list());
        return "stockIncomeBill/view";
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id){
        if(id != null){
            stockIncomeBillService.delete(id);
        }
        return new JSONResult();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StockIncomeBill stockIncomeBill) throws Exception{
        stockIncomeBillService.saveOrUpdate(stockIncomeBill);
        return new JSONResult();
    }

    @RequestMapping("audit")
    @ResponseBody
    public Object audit(Long id) throws Exception{
        stockIncomeBillService.audit(id);
        return new JSONResult();
    }


}
